home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / InstallMaster 7.03 / Devfulldemo.exe / file0151.bin < prev    next >
Encoding:
Text File  |  1999-04-26  |  5.0 KB  |  161 lines

  1. //****************************************************************************
  2. // File: prompt.c
  3. //
  4. // Purpose: example DLL file to interface with Wise Installation System
  5. //
  6. // Functions: LibMain, Prompt, CheckType
  7. //
  8. //
  9. // Programmer:  John McMillan
  10. //
  11. //****************************************************************************
  12.  
  13. #include <windows.h>
  14. #include <string.h>
  15. #include "wisedll.h"
  16. #include "resource.h"
  17.  
  18. #define MAX_PATH_LEN 128
  19.  
  20. void GetVariable(LPDLLCALLPARAMS lpDllParams,char *szVariable,char *szValue);
  21. void SetVariable(LPDLLCALLPARAMS lpDllParams,char *szVariable,char *szValue);
  22. BOOL FAR PASCAL PromptDlg(HWND, UINT, WPARAM, LPARAM);
  23.  
  24. char szPathName[MAX_PATH_LEN]; // Holds the pathname of the install dir
  25. HINSTANCE hDllInst;
  26. char szInstallType[2];  // The type of installation
  27.  
  28. //***********************************************************************
  29. // Function: LibMain
  30. //
  31. // Purpose: C function called from DLL entry point.
  32. //
  33. // Parameters: HINSTANCE hInst;   DLL instance handle
  34. //             WORD wSeg;         DLL data segment selector
  35. //             WORD cbHeapSize;   DLL initial heap size in bytes
  36. //             LPSTR lpszCmdLine; DLL command line
  37. //
  38. // Returns: 1 is success, 0 fail DLL load
  39. //
  40. // Comments:
  41. //
  42. // History:  Date       Author        Reason
  43. //
  44. //****************************************************************************
  45.  
  46. int CALLBACK LibMain(HINSTANCE hInst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
  47. {
  48.    hDllInst = hInst;
  49.    return(1);
  50. }
  51.  
  52. //***********************************************************************
  53. // Function: Prompt
  54. //
  55. // Purpose: Prompt for the destination directory and type of install
  56. //
  57. // Parameters: 
  58. // LPDLLCALLPARAMS lpDllParams; Parameters from Wise
  59. //
  60. // Returns: TRUE if user canceled the install
  61. //
  62. // Comments:
  63. //
  64. // History:  Date       Author        Reason
  65. //
  66. //****************************************************************************
  67.  
  68. BOOL __export CALLBACK Prompt(LPDLLCALLPARAMS lpDllParams)
  69. {
  70.    BOOL bResult;
  71.  
  72.    lstrcpy(szPathName,lpDllParams->lpszParam);
  73.    szInstallType[1] = '\0';
  74.    if (DialogBox(hDllInst,"PromptDlg",lpDllParams->hWnd,PromptDlg) == IDOK) {
  75.       bResult = FALSE;
  76.       SetVariable(lpDllParams,"WISE",szPathName);
  77.       SetVariable(lpDllParams,"TYPE",szInstallType);
  78.    } else {
  79.       bResult = TRUE;
  80.    }
  81.    return bResult;
  82. }
  83.  
  84. BOOL __export CALLBACK PromptDlg(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
  85. {
  86.    switch (message) {
  87.     case WM_INITDIALOG:
  88.       SetDlgItemText(hDlg,IDC_PATHNAME,szPathName);
  89.       CheckRadioButton(hDlg,IDC_COMPLETE_INSTALL,IDC_MINIMUM_INSTALL,
  90.          IDC_COMPLETE_INSTALL);
  91.       return (TRUE);
  92.     case WM_COMMAND:
  93.       if (wParam == IDOK || wParam == IDCANCEL) {
  94.          GetDlgItemText(hDlg,IDC_PATHNAME,szPathName,MAX_PATH_LEN);
  95.          if (IsDlgButtonChecked(hDlg,IDC_COMPLETE_INSTALL)) *szInstallType = 'C';
  96.          if (IsDlgButtonChecked(hDlg,IDC_NETWORK_INSTALL)) *szInstallType = 'N';
  97.          if (IsDlgButtonChecked(hDlg,IDC_MINIMUM_INSTALL)) *szInstallType = 'M';
  98.          EndDialog(hDlg, wParam);
  99.          return (TRUE);
  100.       }
  101.       break;
  102.    }
  103.    return (FALSE);
  104. }
  105.  
  106. BOOL __export CALLBACK CheckType(LPDLLCALLPARAMS lpDllParams)
  107. {
  108.    BOOL bResult;
  109.    char szValue[256];
  110.    
  111.    GetVariable(lpDllParams,"TYPE",szValue);
  112.    if (szValue[0] == lpDllParams->lpszParam[0]) bResult = TRUE;
  113.    else bResult = FALSE;
  114.    return bResult;
  115. }
  116.  
  117. // GetVariable: Returns the value of a variable.
  118. //
  119. // lpDllParams  Parameter structure passed from Wise Installation
  120. // szVariable   Name of the variable (without %'s) to get value for
  121. // szValue      String that will hold the variables value
  122.  
  123. void GetVariable(LPDLLCALLPARAMS lpDllParams,char *szVariable,char *szValue)
  124. {
  125.    WORD i;
  126.    char szVar[32];
  127.  
  128.    *szVar = '%';
  129.    lstrcpy(&szVar[1],szVariable);
  130.    lstrcat(szVar,"%");
  131.    for (i = 0 ; (i < lpDllParams->wCurrReps) &&
  132.       (lstrcmp(&lpDllParams->lpszRepName[i * lpDllParams->wRepNameWidth],szVar) != 0) ; i++) ;
  133.    if (i < lpDllParams->wCurrReps) {
  134.       lstrcpy(szValue,&lpDllParams->lpszRepStr[i * lpDllParams->wRepStrWidth]);
  135.    } else *szValue = '\0';
  136. }
  137.  
  138. // SetVariable: Sets/Creates a variable.
  139. //
  140. // lpDllParams  Parameter structure passed from Wise Installation
  141. // szVariable   Name of the variable (without %'s) to set value for
  142. // szValue      String that contains the variables new value
  143.  
  144. void SetVariable(LPDLLCALLPARAMS lpDllParams,char *szVariable,char *szValue)
  145. {
  146.    WORD i;
  147.    char szVar[32];
  148.  
  149.    *szVar = '%';
  150.    lstrcpy(&szVar[1],szVariable);
  151.    lstrcat(szVar,"%");
  152.    for (i = 0 ; (i < lpDllParams->wCurrReps) &&
  153.       (lstrcmp(&lpDllParams->lpszRepName[i * lpDllParams->wRepNameWidth],szVar) != 0) ; i++) ;
  154.    if (i >= lpDllParams->wCurrReps) {
  155.       if (i >= lpDllParams->wMaxReplaces) return; // Too many variables
  156.       lstrcpy(&lpDllParams->lpszRepName[i * lpDllParams->wRepNameWidth],szVar);
  157.       lpDllParams->wCurrReps++;
  158.    }
  159.    lstrcpy(&lpDllParams->lpszRepStr[i * lpDllParams->wRepStrWidth],szValue);
  160. }
  161.